{%extends 'theme/'+GetConfig('theme')+'/layout.html'%}
{% import 'theme/'+GetConfig('theme')+'/_macro.html' as macros %}

{%block content%}
<div class="layui-container">
    <!-- 看图模式 -->
    <div class="layui-form">
        <div class="layui-form-item">
            <input type="checkbox" name="switch" title="看图模式" lay-filter="image_view" {%if image_mode==1%}checked{%endif%}>
        </div>
    </div>
    <!-- head -->
     {%include 'theme/'+GetConfig('theme')+'/head.html'%}
    <!-- 文件列表 -->
    {%if all_image!=True or image_mode==0%}
    <div class="layui-row">
        <div class="layui-col-lg12">
            <table class="layui-table" lay-filter="filelist">
              <thead>
                <tr>
                  <th lay-data="{field: 'name', width:400, sort: true, fixed: 'left',unresize:true}">标题</th>
                  <th lay-data="{field: 'lastModtime', width:200,unresize:true}" class="layui-hide-xs">修改时间</th>
                  <th lay-data="{field: 'type', width:200, sort: true,unresize:true}" class="layui-hide-xs">类型</th>
                  <th lay-data="{field: 'size', width:200, sort: true,unresize:true}", fixed: 'right'>大小</th>
                </tr>
              </thead>
              <tbody>
                    {%if path.split(':')[-1]!=''%}
                        <tr>
                            <td>
                                <a href="{{list(breadCrumb(path))[-2][1]}}">
                                <i class="fa fa-level-up" aria-hidden="true"></i> 返回上一层</a>
                            </td>
                            <td></td>
                            <td></td>
                            <td></td>
                        </tr>
                    {%endif%}
                    {%for data in items%}
                        {%if data['type']=='folder' %}
                        <tr>
                            <td><a href="{{url_for('front.index',path=data['path'])}}"><i class="fa fa-folder-o"></i> {{data['name']}}</a></td>
                            <td>{{data['lastModtime']}}</td>
                            <td>{{data['type']}}</td>
                            <td>{{data['size']}}</td>
                        </tr>
                        {%else%}
                            {%if image_mode==1%}
                                {%if file_ico(data)!='image'%}
                                <tr>
                                <td><a href="{{url_for('front.index',path=data['path'],action='share')}}" target="_blank">{{ macros.get_ico(file_ico(data)) }} {{data['name']}}</a></td>
                                <td>{{data['lastModtime']}}</td>
                                <td>{{data['type']}}</td>
                                <td>{{data['size']}}</td>
                                </tr>
                                {%endif%}
                            {%else%}
                            <tr>
                                <td><a href="{{url_for('front.index',path=data['path'],action='share')}}" target="_blank">{{ macros.get_ico(file_ico(data)) }} {{data['name']}}</a></td>
                                <td>{{data['lastModtime']}}</td>
                                <td>{{data['type']}}</td>
                                <td>{{data['size']}}</td>
                            </tr>
                            {%endif%}
                        {%endif%}
                    </tr>
                    {%endfor%}
              </tbody>
            </table>
        </div>
    </div>
    {%endif%}
    {%if image_mode==1%}
    <center>
        <div style="max-width: 600px;">
        {%for data in items%}
            {%if file_ico(data)=='image'%}
                <a href="{{url_for('front.index',path=data['path'],action='share')}}" target="_blank">
                <img class="img-responsive" src="{{url_for('front.show',fileid=data['id'],user=cur_user,action='download')}}"/>
                </a>
            {%endif%}
        {%endfor%}
        </div>
    </center>
    {%endif%}
    {%if pagination%}
    <center>
        {% if pagination %}
            {{ macros.pagination_widget(pagination, endpoint,path=path,sortby=sortby,order=order) }}
        {% endif %}
    </center>
    {%endif%}

    <!-- readme -->
    {%include 'theme/'+GetConfig('theme')+'/readme.html'%}
</div>
{%endblock content%}
{%block script%}
<script>
layui.use('table', function(){
    var table = layui.table;
    table.init('filelist', {
        limit: 50 //注意：请务必确保 limit 参数（默认：10）是与你服务端限定的数据条数一致
    });
});

function setCookie(c_name, value, exdays) {
    var exdate = new Date();
    exdate.setDate(exdate.getDate() + exdays);
    var c_value = escape(value) + ((exdays == null) ? "" : "; expires=" + exdate.toUTCString());
    document.cookie = c_name + "=" + c_value;
}

layui.use('form', function() {
    var form = layui.form;
    form.on('checkbox(image_view)', function(data) {
        var ckname = 'image_mode';
        if (data.elem.checked) {
            setCookie(ckname, 0, 1);
            window.location.href = "{{url_for('front.index',path=path,image_mode=1)}}";
        } else {
            setCookie(ckname, 1, 1);
            window.location.href = "{{url_for('front.index',path=path,image_mode=0)}}";
        }
    });
});


</script>
{%endblock script%}
